package com.dci.service.impl.construction;

import com.dci.dao.pms.construction.ConstructionInfoMapper;
import com.dci.model.construction.ConstructionInfo;
import com.dci.result.JsonData;
import com.dci.result.PageResult;
import com.dci.service.construction.ConstructionInfoService;
import com.dci.util.UUIDBuild;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


/**
 * All rights Reserved, Designed By 姑苏区政府大数据中心
 *
 * @version V1.0
 * @Title: null.java
 * @Package com.dci.service.impl.construction
 * @Description: 接口实现类
 * @author: 张星亮
 * @date: 2019/2/25
 * @Copyright: 2019 姑苏区政府大数据中心. All rights reserved.
 * 注意：本内容仅限于姑苏区政府大数据中心内部传阅，禁止外泄以及用于其他的商业目
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ConstructionInfoServiceImpl implements ConstructionInfoService {

    @Resource
    private ConstructionInfoMapper constructionInfoMapper;

    /**
     * 新增
     *
     * @param record
     * @return
     */
    @Override
    public JsonData insert(ConstructionInfo record) {
        record.setId(UUIDBuild.getUUID());
        constructionInfoMapper.insert(record);
        return JsonData.success(record, 906);
    }

    /**
     * 查询
     *
     * @param record
     * @return
     */
    @Override
    public JsonData selectByPrimaryKey(ConstructionInfo record) {
        record = constructionInfoMapper.selectByPrimaryKey(record);
        return JsonData.success(record, 906);
    }

    /**
     * 修改
     *
     * @param record
     * @return
     */
    @Override
    public JsonData updateByPrimaryKeySelective(ConstructionInfo record) {
        constructionInfoMapper.updateByPrimaryKeySelective(record);
        return JsonData.success(record, 906);
    }

    /**
     * 查询所有
     *
     * @param record
     * @return
     */
    @Override
    public PageResult selectPageList(ConstructionInfo record) {
        PageHelper.startPage(record.getPageNum(), record.getPageSize());
        List<ConstructionInfo> list = constructionInfoMapper.selectPageList(record);
        PageInfo<ConstructionInfo> pageInfo = new PageInfo<>(list);
        Long count = pageInfo.getTotal();
        return PageResult.success(list, null, null, count);
    }

    /**
     * 删除
     *
     * @param list
     * @return
     */
    @Override
    public JsonData batchDelete(List<ConstructionInfo> list) {
        String flag = "1";
        list.forEach(con -> con.setDelFlag(flag));
        constructionInfoMapper.batchDelete(list);
        return JsonData.success(list, 906);
    }
}
